<?php defined('IN_YuLin') || exit('NO PERMIT!'); ?>
{template index/header}
<style>
.tag_set_box { width: 120%; height: 150px; border: solid 1px #ccc; position: absolute; display: none; z-index: 999; background: #fff; top: -150px; left:-70px; }
</style>
<div class="x-nav">
	<span class="layui-breadcrumb">
		<a>首页</a>
		<a>彩票管理</a>
		<a>彩种管理</a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
		<i class="layui-icon" style="line-height:30px">ဂ</i>
	</a>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin:3px 5px 0 0;float:right" href="{U('lottery/credit_typelist')}">
		<i class="layui-icon" style="line-height:30px">信用彩种开奖类型</i>
	</a>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin:3px 5px 0 0;float:right" href="?m={$m}&c={$c}&a=add_lott" title="添加">
		<i class="layui-icon" style="line-height:30px">添加</i>
	</a>
</div>

<div class="x-body">
	<form action="?" method="post" >
		<input type="hidden" name="m" value="{$m}" />
		<input type="hidden" name="c" value="{$c}" />
		<input type="hidden" name="a" value="sort" />
		<table class="layui-table">
			<thead>
                <tr>
                    <th width="5%"><input type="checkbox" value="" id="check_box" onclick="selectall('ids[]');"></th>
                    <th width="10%">ID</th>
                    <th width="15%">彩种名称</th>
                    <th width="10%">期数说明</th>
                    <th width="5%">图标</th>
                    <th width="10%">类型</th>
                    <th width="10%">销售</th>
                    <th width="10%">彩种类型</th>
        			<th>操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $data as $val}
                <tr>
                    <td class="text-c"><input class="inputcheckbox " name="ids[]" value="{$val['id']}" type="checkbox"></td>
                    <td class="text-c">{$val['id']}</td>
                    <td class="text-c">{$val['title']}</td>
                    <td class="text-c">{$val['per_explain']}</td>
                    <td class="text-c">
                        {if $val['thumb']}
                        <a href="../{$val['thumb']}" class="fancybox"><img src="../{$val['thumb']}" /></a>
                        {/if}
                    </td>
                    <td class="text-c">
                        {if $val['credit']}<font color="green">信用</font>{else}<font color="red">官方</font>{/if}
                    </td>
                    <td class="text-c">
                        {if $val['sales']}<font color="green">销售中</font>{else}<font color="red">暂停销售</font>{/if}
                    </td>
					<td class="text-c">{$cateIdKey[$val['cate_id']]['name']}</td>
                    <td class="text-c" style="position: relative;">
                    	{if $val['credit']}
                    		<a href="javascript:void(0);" style="color: red;" class="tag_set_credit" ami="{$val['id']}">设置开奖方式</a> | 
                    		<div class="tag_set_box" ami="{$val['id']}">
                				<div style="padding-top: 20px;">
                    				<div style="width: 35%; float: left;">选择开奖类型：</div>
                    				<div style="width: 65%; float: left;">
                        				<select name="" style="width: 100%; " class="tag_get_select" ami="{$val['id']}" id="id_get_select_{$val['id']}">
                        					<option value="">请选择</option>
                        					{loop $creditTypeList as $ctk => $ctv}
                        						<option value="{$ctv['id']}">{$ctv['title']}</option>
                        					{/loop}
                        				</select>
                        			</div>
                    			</div>
                    			<div> 
                    				<div style="width: 35%; float: left;">设置开奖参数：</div>
                    				<div style="width: 65%; float: left;">
                    					<select style="float: left; width: 100%; " class="tag_set_with_lottery" id="id_open_param_sel_{$val['id']}" ami="{$val['id']}">
                    						<option value="">--请选择--</option>
                    						{loop $lottList as $lk => $lv}
                        						{if $val['cate_id'] == $lv['cate']}
                        							<option value="{$lv['id']}">{$lv['title']}</option>
                        						{/if}
                    						{/loop}
                    					</select>
                    					<input type="text" class="tag_open_param" id="id_open_param_{$val['id']}" name="open_param" ami="{$val['id']}" style="width: 100%;" value=""/>
                    				</div>
                    			</div>
                    			<div><input type="button" value="设置" class="tag_do_set" ami="{$val['id']}"/>&nbsp;&nbsp;&nbsp;<input type="button" value="返回" class="tag_close_set"/></div>
                    		</div>
                    	{/if}
                        <a href="?m={$m}&c={$c}&a=add&id={$val['id']}">编辑</a>
                    </td>
                </tr>
                {/loop}
            </tbody>
		</table>
		<div id="pages" class="layui-laypage">{$multi}</div>
	</form>
</div>
<script>
$('.tag_set_credit').on('click', '', function (){
	if ($('.tag_set_box[ami="' + $(this).attr('ami') + '"]').is(':hidden') == false) {
		$('.tag_set_box[ami="' + $(this).attr('ami') + '"]').hide();
		return;
	}
	$('.tag_set_box').hide();
	$('.tag_set_box[ami="' + $(this).attr('ami') + '"]').show();
	// 有值则不获取内容
	if($('#id_open_param_' + $(this).attr('ami')).val() != '') return;
	var ami        = $(this).attr('ami');
	var type_id    = $('#id_get_select_' + ami).val();
	
	$('#id_open_param_' + ami).hide();
	$('#id_open_param_sel_' + ami).hide();
	// 载入预设数据
	$.ajaxSetup({async:false});
	var param = {'operation':'getSetCreditInfo', 'lott_id':$(this).attr('ami')};
	var data  = 'data=' + JSON.stringify(param);
	var ami   = $(this).attr('ami');
	var obj   = $(this);
	$.post("{U('json/lottery')}", data, function (res){
		if($.isEmptyObject(res.creditSet)) return;
		$.each(res.creditSet, function (i, v){
			if(v.status == 1){
				$('#id_get_select_' + ami + ' option[value="' + v.type_id + '"]').prop('selected', true);
				$('#id_open_param_' + ami).val(v.open_param);
				
				if(v.type_id == 2){
					// 
					$('#id_open_param_sel_' + ami).show();
					$('#id_open_param_sel_' + ami + ' option[value="' + v.open_param + '"]').prop('selected', true);
				}else{
					$('#id_open_param_' + ami).show();
				}
				// 跳出
				return false;
			}
		})
		console.log(res);
	}, 'json')
})
$('.tag_close_set').on('click', '', function (){
	$('.tag_set_box').hide();
})

$('.tag_do_set').on('click', '', function (){
	var open_param = '';
	var ami        = $(this).attr('ami');
	if(!$('#id_open_param_sel_' + ami).is(':hidden')){
		open_param = $('#id_open_param_sel_' + ami).val();
	}else{
		open_param = $('#id_open_param_' + ami).val();
	}
	$.ajaxSetup({async:false});
	var setData = {'type_id': $('.tag_get_select[ami="' + $(this).attr('ami') + '"]').val(), 'open_param':$('.tag_open_param[ami="' + $(this).attr('ami') + '"]').val(), 'lott_id':$(this).attr('ami')}
	param       = {'operation':'setCreditOpen', 'setData':setData};
	var data    = 'data=' + JSON.stringify(param);
	$.post("{U('json/lottery')}", data, function (res){
		$('.tag_set_box').hide();
		console.log(res);
	}, 'json')
})

$('.tag_get_select').on('change', '', function (){
	var ami      = $(this).attr('ami');
	var type_id  = $(this).find("option:selected").val();
	$('#id_open_param_' + ami).hide();
	$('#id_open_param_sel_' + ami).hide();
	if(type_id == 2){
		$('#id_open_param_sel_' + ami).show();
	}else{
		$('#id_open_param_' + ami).show();
	}
	// 载入预设数据
	$.ajaxSetup({async:false});
	var param = {'operation':'getSetCreditInfo', 'lott_id':$(this).attr('ami')};
	var data  = 'data=' + JSON.stringify(param);
	$.post("{U('json/lottery')}", data, function (res){
		if($.isEmptyObject(res.creditSet)) return;
		$.each(res.creditSet, function (i, v){
			if(v.type_id == type_id){
				$('#id_open_param_' + ami).val(v.open_param);
				if(!$('#id_open_param_sel_' + ami).is(':hidden')){
					$('#id_open_param_sel_' + ami + ' option[value="' + v.open_param + '"]').attr('selected', true);
				}
				// 跳出
				return false;
			}
		})
	}, 'json')
})

$('.tag_set_with_lottery').on('change', '', function (){
	console.log($('#id_open_param_' + $(this).attr('ami')).val());
	$('#id_open_param_' + $(this).attr('ami')).val($(this).val());
})
</script>
{template index/footer}